package com.ge.modules.api.service.impl;

import com.ge.common.exception.RRException;
import com.ge.common.validator.Assert;
import com.ge.modules.api.service.TbTechnicianService;
import com.ge.modules.dao.TbTechnicianDao;
import com.ge.modules.entity.TbTechnicianEntity;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;




@Service
public class TbTechnicianServiceImpl implements TbTechnicianService {

	@Autowired
	private TbTechnicianDao technicianDao;

	@Override
	public TbTechnicianEntity queryByObject(TbTechnicianEntity technician) {
		return technicianDao.queryObject(technician);
	}

	@Override
	public TbTechnicianEntity queryByTechnicianId(Integer technicianId){
		return technicianDao.queryById(technicianId);
	}
	
	@Override
	public List<TbTechnicianEntity> queryList(Map<String, Object> map){
		return technicianDao.queryList(map);
	}

	@Override
	public List<TbTechnicianEntity> queryList(TbTechnicianEntity technician) {
		return technicianDao.queryList(technician);
	}

	@Override
	public List<TbTechnicianEntity> queryListObject(TbTechnicianEntity technician) {
		return technicianDao.queryListObject(technician);
	}

	@Override
	public int queryTotal(Map<String, Object> map){
		return technicianDao.queryTotal(map);
	}
	
	@Override
	public void save(TbTechnicianEntity technician){
		technicianDao.save(technician);
	}
	
	@Override
	public void update(TbTechnicianEntity technician){
		technicianDao.update(technician);
	}
	
	@Override
	public void delete(Long technicianId){
		technicianDao.delete(technicianId);
	}
	
	@Override
	public void deleteBatch(Long[] technicianIds){
		technicianDao.deleteBatch(technicianIds);
	}

	@Override
	public Integer login(String mobile, String password) {
		TbTechnicianEntity technician = technicianDao.queryByMobile(mobile);
		Assert.isNull(technician,"用户名或密码错误");
		//密码错误
		if (!technician.getPassword().equals(DigestUtils.sha256Hex(password))){
			throw new RRException("用户名或密码错误");
		}
		return technician.getTechnicianId();
	}

	@Override
	public TbTechnicianEntity queryByMobile(String mobile) {
		return technicianDao.queryByMobile(mobile);
	}

}
